home *** CD-ROM | disk | FTP | other *** search
- /* DELAY.C - delays for a given time or until a given time-of-day */
-
- /* Copyright 1989 (c) by Robert F. Bohn Jr. (Quickie Software) */
- /* For more information, contact me via these: */
- /* CompuServe 72321,477 */
- /* FidoNet 1:236/6.1 */
- /* Compiled with QuickC 2.00 07/05/89 */
-
- #include <stdio.h>
- #include <graph.h>
- #include <ctype.h>
- #include <time.h>
-
- #define TRUE 1
- #define FALSE 0
- #define ON 1
- #define OFF 0
-
-
- #define DEBUG TRUE
- #define MAXLEN 133
-
-
- void setcurpos(row, col)
- int row, col;
- {
- row = ((row>25) ? 25 : row);
- row = ((row< 1) ? 1 : row);
- col = ((col>79) ? 79 : col);
- col = ((col< 1) ? 1 : col);
- _settextposition( (short) row, (short) col );
- }
-
-
- void display_syntax()
- {
- printf("\n");
- printf(" Correct syntax is one of the following:\n");
- printf("\n");
- printf(" DELAY FOR hh HOUrs\n");
- printf(" DELAY FOR mm MINutes\n");
- printf(" DELAY FOR ss SEConds\n");
- printf(" DELAY UNTIL hh:mm\n");
- printf("\n");
- printf(" ╔═══════════════════════════════════════════════════════════╗\n");
- printf(" ║ If you liked this utility, or have suggestions on how to ║\n");
- printf(" ║ improve it, send a message to Rob Bohn via one of these: ║\n");
- printf(" ║ 72321,477 CompuServe ║\n");
- printf(" ║ 1:236/6.1 FidoNet ║\n");
- printf(" ╚═══════════════════════════════════════════════════════════╝\n");
- printf("\n");
- }
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- char *digit1_ptr, *digit2_ptr, *colon_ptr, *digit3_ptr, *digit4_ptr;
- char current_time[9], until_time[9],
- until_hh_s[3], until_mm_s[3], until_ss_s[3];
- struct rccoord oldpos;
- int time_ok, until_hh, until_mm, until_ss, until_arg;
-
-
- if ( (argc<3) || (argc>4) )
- {
- printf("ERROR:\a you must supply either two or three arguments.\n");
- display_syntax();
- exit(1);
- }
-
- (void) strupr( argv[1] ); /* will upper case arg1, returns ptr as OK flag */
- if ( (strcmp(argv[1], "UNTIL") != 0) &&
- (strcmp(argv[1], "FOR") != 0) )
- {
- printf("ERROR:\a The first argument must be the word 'UNTIL' or 'FOR'.\n");
- display_syntax();
- exit(2);
- }
-
- if (strcmp(argv[1], "UNTIL") == 0)
- {
- time_ok = TRUE;
- if ( !isdigit( *(argv[2] ) ) )
- time_ok = FALSE;
- if ( !isdigit( *(argv[2]+1) ) )
- time_ok = FALSE;
- if ( *(argv[2]+2) != ':' )
- time_ok = FALSE;
- if ( !isdigit( *(argv[2]+3) ) )
- time_ok = FALSE;
- if ( !isdigit( *(argv[2]+4) ) )
- time_ok = FALSE;
-
- if (time_ok == FALSE)
- {
- printf("ERROR:\a Time must be stated as 'HH:MM' after the word 'UNTIL'.\n");
- display_syntax();
- exit(3);
- }
- }
-
- if (strcmp(argv[1], "FOR") == 0)
- {
- time_ok = TRUE;
- if ( !isdigit( *(argv[2] ) ) )
- time_ok = FALSE;
- if ( !isdigit( *(argv[2]+1) ) )
- time_ok = FALSE;
-
- if (time_ok == FALSE)
- {
- printf("ERROR:\a Time must be two digits after the word 'FOR'.\n");
- display_syntax();
- exit(4);
- }
- (void) strupr( argv[3] ); /* will upper case arg3, returns ptr as OK flag */
- *(argv[3]+3) = '\0'; /* to set to 3 or less characters */
- if ( (strcmp(argv[3], "HOU") != 0) &&
- (strcmp(argv[3], "MIN") != 0) &&
- (strcmp(argv[3], "SEC") != 0) )
- {
- printf("ERROR:\a The time must be followed by at least the first\n");
- printf(" three letters of the words HOURS, MINUTES, or SECONDS.\n");
- display_syntax();
- exit(5);
- }
- }
-
- _strtime( current_time );
-
- if (strcmp(argv[1], "UNTIL") == 0)
- {
- strcpy(until_time, argv[2]);
- until_time[5] = ':';
- until_time[6] = '0';
- until_time[7] = '0';
- until_time[8] = '\0';
- }
-
- if (strcmp(argv[1], "FOR") == 0)
- {
- strcpy(until_time, current_time);
-
- until_hh_s[0] = until_time[0];
- until_hh_s[1] = until_time[1];
- until_hh_s[2] = '\0';
- until_hh = atoi(until_hh_s);
-
- until_mm_s[0] = until_time[3];
- until_mm_s[1] = until_time[4];
- until_mm_s[2] = '\0';
- until_mm = atoi(until_mm_s);
-
- until_ss_s[0] = until_time[6];
- until_ss_s[1] = until_time[7];
- until_ss_s[2] = '\0';
- until_ss = atoi(until_ss_s);
-
- until_arg = atoi(argv[2]);
-
- if (strcmp(argv[3], "SEC") == 0)
- until_ss = until_ss + until_arg;
- if (until_ss > 59)
- {
- until_ss -= 60;
- until_mm++;
- }
-
- if (strcmp(argv[3], "MIN") == 0)
- until_mm = until_mm + until_arg;
- if (until_mm > 59)
- {
- until_mm -= 60;
- until_hh++;
- }
-
- if (strcmp(argv[3], "HOU") == 0)
- until_hh = until_hh + until_arg;
- if (until_hh > 23)
- until_hh -= 24;
-
- sprintf( until_time, "%2.2d:%02.2d:%02.2d", until_hh, until_mm, until_ss);
- }
-
- printf("Delay v0.3 - delaying until %s; current time is %s",
- until_time, current_time);
- oldpos = _gettextposition();
-
- while (strcmp(current_time,until_time) != 0)
- {
- _strtime( current_time );
- if (current_time[7] == '0')
- {
- setcurpos(oldpos.row, 55);
- printf("%s",current_time);
- }
- }
-
- printf("\nDelay complete\a");
- exit(0);
- }
-